10. Exercise 2: Solution

1. Fill in the SMA, and RSI Columns for T=5 to T=9.

1.1 Calculations - SMA:

T Close Price 5-day sum SMA
0 100
1 102
2 101
3 104
4 103
5 106 510 102
6 107 516 103
7 108 521 104
8 105 528 106
9 110 529 106

1.2 Calculations - RSI:

T Close Price Price Change Avg Gain past 5 days Avg Loss past 5 days RS RSI (round to integer)
0 100
1 102 +2
2 101 -1
3 104 +3
4 103 -1
5 106 +3 8/5 2/5 4 80
6 107 +1 7/5 2/5 3.5 78
7 108 +1 8/5 1/5 8 89
8 105 -3 5/5 4/5 1.25 56
9 110 +5 10/5 3/5 3.33 77

1.3 Solution:

T Close Price Volume 5-Day SMA of  Close Price 5-Day RSI Of Close Price
0 100 1200
1 102 1350
2 101 1400
3 104 1500
4 103 1250 102
5 106 1100 103.2 80
6 107 1400 104.2 78
7 108 1800 105.6 89
8 105 1500 105.8 56
9 110 1400 107.2 77

2. Display the feature vectors for T=5, 6, 7, 8, and 9 with the format: [Close_t, Volume_t, SMA_t, RSI_t]

T=5: [ 106, 1100, 103.2, 80 ]

T=6: [ 107, 1400, 104.2, 78 ]

T=7: [ 108, 1800, 105.6, 89 ]

T=8: [ 105, 1500, 105.8, 56 ]

T=9:  [ 110, 1400, 107.2, 77 ]

3. Display the state space matrices for T=6, 7, 8, and 9, with a window size of 2.

T=6:

[     [ 106, 1100, 103.2, 80 ] ,

    [ 107, 1400, 104.2, 78 ]  ]

T=7:

[     [107, 1400, 104.2, 78 ] ,

    [ 108, 1800, 105.6, 89 ]  ]

T=8:

[     [ 108, 1800, 105.6, 89 ] ,

    [ 105, 1500, 105.8, 56 ] ]

T=9:

[     [105, 1500, 105.8, 56 ] ,

    [ 110, 1400, 107.2, 77 ]  ]